Tensor network utils
I/O functions for tensors and mps (list of tensors).
Furthermore, the class QCOperators for handling operators is provided.
Functions and classes
- class qmatchatea.utils.tn_utils.QCOperators[source]
Class to store and save to file operators. To add an operator to the list use self[‘op_name’] = op_tensor.
It starts with the pauli operators already defined, with keywords “X”,”Y”,”Z”
- qmatchatea.utils.tn_utils.read_mps(filename, cmplx=True)[source]
Read an MPS from a given file. Reads in column-major order but the output is in row-major.
This function was used to exchange the MPS with the Fortran backend (thus the different ordering), which is now deprecated.
Parameters
- filename: str
PATH to the file
- cmplx: bool, optional
If True the MPS is complex, real otherwise. Default to True
Returns
- mps: list
list of np.array in row-major order
- qmatchatea.utils.tn_utils.write_mps(filename, mps, cmplx=True)[source]
Write an MPS to file. The tensor is written in Fortran-like indexing, i.e. the MPS tensors will be converted from row-major into column-major order.
This function was used to exchange the MPS with the Fortran backend (thus the different ordering), which is now deprecated.
Parameters
- filename: str
PATH to the file
- mps: list
List of tensors forming the mps
- cmplx: bool, optional
If True the MPS is complex, real otherwise. Default to True
Returns
None
- qmatchatea.utils.tn_utils.write_tensor(tensor, dest, cmplx=True, sparse=False)[source]
Write a tensor stored in a numpy matrix to a file. Conversion to column major is taken care of here.
Arguments
- tensornp.ndarray
Tensor to be written to the file.
- deststr, or filehandle
If string, file will be created or overwritten. If filehandle, then data will be written there.
- sparse: bool
If True write the tensor in a sparse format, i.e. each row is written as idx elem where idx is the position of the element elem in the tensor vector